const all = (arr) => {
  return new Promise((resolve, reject) => {
    if (!Array.isArray(arr)) {
      reject(new Error("请传入数组"));
    }
    const result = [];
    let successCount = 0;
    arr.forEach((item, index) => {
      item
        .then((a) => {
          result[index] = a;
          successCount++;
          if (successCount === arr.length) {
            resolve(result);
          }
        })
        .catch((fail) => {
          reject(fail);
        });
    });
  });
};

all([p1, p2]).then((res) => {});
